package GameEngine.Collision;

public class Circle extends CollisionObject {
	private int r;
	private int rSquared;

	public Circle(int px, int py, int rx) {
		posx = px;
		posy = py;
		r = rx;
		rSquared = r * r;
	}

	@Override
	public boolean inside(Point p) {
		return (distSquared(p) <= rSquared);
	}

	private int distSquared(Point p) {
		return ((p.x - posx) * (p.x - posx)) + ((p.y - posy) * (p.y - posy));
	}

	@Override
	public boolean overlap(CollisionObject co) {
		if (co instanceof Circle) {
			Circle c = (Circle) co;
			return ((this.posx - c.posx) * (this.posx - c.posx) + (this.posy - c.posy)
					* (this.posy - c.posy)) <= (this.r + c.r) * (this.r + c.r);
		}
		return false;
	}

}
